package com.open.jack.jk_mpchart

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet
import android.view.MotionEvent
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.components.YAxis
import com.open.jack.jk_mpchart.listener.IBarChartListener
import com.open.jack.jk_mpchart.model.JkEntry

class JkBarChart : BarChart , IChartBase {

    constructor(context: Context) : super(context) {
        initChart(null)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {

        initChart(attrs)
    }


    protected fun initChart( attrs: AttributeSet?) {

    }

    private val barChart= JkBarChartUtil()

    override fun initChart(){
        barChart.initCharView(this)
    }

    fun addBarDataList(barData:List<Float>){
        barChart.addBarDataList(barData)
    }

    fun addChartData(list:List<JkEntry>){
        barChart.addData(list)
    }

    override fun setXAxisLabel(xIndex:Int, label:String) {
        barChart.setXAxisLabel(xIndex,label)
    }

    fun setBarColor(color:String){
        barChart.setBarColor(color)
    }

    fun setBarColors(colors:List<String>){
        barChart.setBarColors(colors)
    }

    public override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
        super.onSizeChanged(w, h, oldw, oldh)
    }

    public override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
    }

    public override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
    }

    public override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        return super.onTouchEvent(event)
    }

//    fun setMinOffset(offset:Float ){
//        barChart.setMinOffset(offset)
//    }

    fun setLeftAxisOffset(offset:Float ){
        barChart.setLeftAxisOffset(offset)
    }

    fun setLeftAxiGridColor(color:String){
        barChart.setLeftAxiGridColor(color)
    }

    override fun setLeftAxisTextColor(color:String){
        barChart.setLeftAxisTextColor(color)
    }
    fun setXAxisTextSize(size:Float ){
        barChart.setXAxisTextSize(size)
    }


    fun setLeftAxisTextSize(size:Float ){
        barChart.setLeftAxisTextSize(size)
    }

    override fun setXAxisTextColor(color:String){
        barChart.setXAxisTextColor(color)
    }

    fun setBarChartListener(listener: IBarChartListener){
        barChart.setBarChartListener(listener)
    }
    fun clearHighlight(){
        barChart.clearHighlight()
    }

    override fun updateView(){
        barChart.updateView()
    }
}